import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CnGiftAnimationView extends StatefulWidget {
  final String giftName;
  final AnimationController controller;
  final AnimationController scaleController;


  const CnGiftAnimationView(this.giftName,{super.key,required this.controller,required this.scaleController});

  @override
  State<StatefulWidget> createState() => ViewState();
}

class ViewState extends State<CnGiftAnimationView>  {

  late Animation<double> _rotationAnimation;
  late Animation<double> _scaleAnimation;
  late Animation<double> _opacityAnimation;


  @override
  void initState() {
    super.initState();


    /// 创建旋转动画
    _rotationAnimation = Tween<double>(
      begin: 0,
      end: 1, // 360度的弧度
    ).animate(widget.scaleController);

    /// 创建缩放动画
    _scaleAnimation = Tween<double>(
      begin: 0,
      end: 1,
    ).animate(widget.controller);

    ///显隐动画
    _opacityAnimation =
        Tween<double>(begin: 0.0, end: 1.0).animate(widget.controller);

  }


  @override
  Widget build(BuildContext context) {


    return AnimatedBuilder(
          animation: widget.controller,
          builder: (BuildContext context, Widget? child) {
            return Opacity(
                opacity: _opacityAnimation.value,
                child: ScaleTransition(
                    scale: _scaleAnimation,
                    child: SizedBox(
                        width: 316,
                        height: 316,
                        child: Stack(fit: StackFit.expand, children: [
                          RotationTransition(
                              turns: _rotationAnimation,
                              child: Image.asset(
                                "images/ic_gift_bg.webp",
                                width: double.infinity,
                                height: double.infinity,
                              )),
                          Image.asset(
                            widget.giftName,
                            width: double.infinity,
                            height: double.infinity,
                          ),
                        ]))));
          });

  }

  @override
  void dispose() {
    super.dispose();
  }
}
